<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            position: relative;
            width: 400px;
            border-bottom: 1px solid #ccc;
            margin: 100px auto;
        }
        .box input  {
            width: 370px;
            height: 30px;
            border: 0;
            outline: none;
        }
        .box img {
            position: absolute;
            top: 5px;
            right: 2px;
            width: 24px;
            height: 24px;
        }
    </style>
</head>
<body>
    <div class="box">
        <label for=""><img src="images/1122879666_1184688902_88_88.png" alt="" id="eye"></label>
        <input type="password" name="" id="psw">
    </div>
    <script>
        // 1.获取元素
        var flag = 0;
        var eye = document.getElementById('eye');
        var psw = document.getElementById('psw');
        eye.onclick = function() {
            if (flag == 0) {
                //点击一次之后；flag要变化
                psw.type = 'text';
                flag  = 1;
                eye.src = 'images/p1.png';
            }else {
                psw.type = 'password';
                eye.src ='images/1122879666_1184688902_88_88.png'
                flag  = 0;
            }
           

        }
    </script>
</body>
</html>